﻿using Albatross.Shell.Configuration;
using Albatross.WPF.Common;
using Albatross.WPF.Common.Views;
using Albatross.WPF.Common.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Albatross.Shell.ViewModels {
	public class SystemsViewModel : WorkspaceViewModel {
		public SystemsViewModel() {
			Title = "Systems";
			Modules = new ObservableCollection<WorkspaceViewModel>();
		}

		public ObservableCollection<WorkspaceViewModel> Modules { get; private set; }
		public override void LoadAsync(WPF.Common.IViewService viewService) {
			Modules.Clear();
			foreach (ModuleCfgElement cfgElem in Configuration.ShellCfgSection.GetConfiguration(true).Modules) {
				ModuleViewModel vm = new ModuleViewModel(cfgElem);
				Modules.Add(vm);
			}
		}

		public RelayCommand<CommandParameter> SelectedModuleChangedCommand { get { return new RelayCommand<CommandParameter>(SelectedModuleChanged); } }
		void SelectedModuleChanged(CommandParameter cmdParam) {
			WorkspaceViewModel workspace = cmdParam.Value as WorkspaceViewModel;
			cmdParam.ViewService.ShowWorkspace(WorkspaceConstructExt.CreateByObject(workspace));
		}
	}
}
